/*
 * @Author: TLL
 * @Date: 2021-02-24 11:04:46
 * @version: v1.1
 * @Descripttion: 
 * @LastEditors: TLL
 * @LastEditTime: 2021-05-06 09:38:25
 * @Auditor: TLL
 */
import React, { memo, useMemo } from 'react';
import Select from './Select';
import { SelectProps, CompanyCode } from './interface';

interface ConsoleSelectProps extends SelectProps { 
  code: string;
  disabled?: boolean;
  placeholder?: string
}

const url = '/bk/api/company/CompanyCode/findOne';
const fieldNames = { value: 'codeValue', label: 'codeDesc' };

function rtnDataAfter(data: CompanyCode){
  return data.CompanyCodeValues
}

export default memo(({ code, onChange, value, id, extra, disabled, required, placeholder }: ConsoleSelectProps) => {

  const query = useMemo(() => ({
    where: { code },
    include: [{ model: 'CompanyCodeValue' }]
  }), [code]);
  
  return (
    <Select 
      id={id}
      extra={extra}
      value={value}
      cacheKey={`Cconsole.${code}`}
      onChange={onChange as any}
      rtnDataAfter={rtnDataAfter} 
      query={query} 
      disabled={disabled}
      fieldNames={fieldNames} 
      required={required}
      placeholder={placeholder}
      url={url} />
  )
})